<?php
$app->group('/account', function () use ($app) {
    $app->get('/login', function () use ($app) {
        $app->render('account/login.html', array('models' => array()));
    })->name('account-login');
    $app->post('/login', function () use ($app) {
        $email = $app->request->post('email');
        $password = $app->request->post('password');
        $results = $app->UserTable->select(array('email=?'=>$email,'password'=>md5($password),'enabled'=>true));
        if ($results && $results->count() > 0) {
            $_SESSION['user'] = $results->current();
            $app->redirect($app->urlFor('home'), 302);
        } else {
            $app->flash('error', 'email and password can not match');
            $app->flash('email', $email);
            $app->redirect($app->urlFor('account-login'), 302);
        }
    });

    $app->get('/forgot-password', function () use ($app) {
        $app->render('account/forgot-password.html');
    })->name('account-forgot-password');
    $app->post('/forgot-password', function () use ($app) {
    });

    $app->get('/join', function () use ($app) {
        $app->render('account/join.html');
    })->name('account-join');
    $app->post('/join', function () use ($app) {
    });
});
